package com.zxhhyj.storm

import com.zxhhyj.storm.common.SQL
import com.zxhhyj.storm.schema.Table
import kotlin.test.Test

class SqlUnitTest {

    class User(
        val id: Int,
        val name: String,
        val location: String?,
        val enabled: Boolean,
    )

    private object UserTable : Table<User>("t_user") {
        val id = int("id").primaryKey(true).bindTo(User::id)
        val name = varchar("name").bindTo(User::name)
        val location = varchar("location").default("unknown").bindTo(User::location)
        val enable = boolean("enable").default(false).bindTo(User::enabled)
    }

    @Test
    fun createTable() {
        val sql = SQL.createTableStr(UserTable)
        println(sql)
    }

    @Test
    fun insertIntoData() {
        val sql = SQL.insertIntoStr(
            UserTable,
            mapOf(
                UserTable.id.fieldName to "1",
                UserTable.name.fieldName to "ZXHHYJ",
                UserTable.location.fieldName to "Shenzhen",
                UserTable.enable.fieldName to true
            )
        )
        println(sql)
    }

    @Test
    fun batchInsertIntoData() {
        val sql = SQL.batchInsertIntoStr(
            UserTable,
            listOf(
                mapOf(
                    UserTable.id.fieldName to "1",
                    UserTable.name.fieldName to "ZXHHYJ",
                    UserTable.location.fieldName to "Shenzhen",
                    UserTable.enable.fieldName to true
                ),
                mapOf(
//                    UserTable.id.fieldName to "2",
                    UserTable.name.fieldName to "只想呵呵一句",
                    UserTable.location.fieldName to "Guangxi",
                    UserTable.enable.fieldName to false
                ),
            )
        )
        println(sql)
    }
}